package com.pc.scrs.controller;

import com.pc.scrs.bean.vo.pageInfo.MySelectListVoPageInfo;
import com.pc.scrs.bean.vo.pageInfo.RecommendListVoPageInfo;
import com.pc.scrs.bean.vo.pageInfo.RequiredListVoPageInfo;
import com.pc.scrs.bean.vo.pageInfo.SelectListVoPageInfo;
import com.pc.scrs.service.IRecommendService;
import com.pc.scrs.service.ISelectService;
import com.pc.scrs.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/select")
public class SelectController {

    @Resource
    private ISelectService selectService;

    @Resource
    private IRecommendService recommendService;


    @GetMapping("/requiredList")
    public ResponseResult requiredList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", required = false, defaultValue = "7") Integer pageSize
    ) {
        RequiredListVoPageInfo pageInfo = selectService.requiredList(pageNum, pageSize);
        return new ResponseResult(200, "ok", pageInfo);
    }

    @GetMapping("/selectList")
    public ResponseResult selectList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "7") Integer pageSize
    ) {
        SelectListVoPageInfo pageInfo = selectService.selectList(pageNum, pageSize);
        return new ResponseResult(200, "ok", pageInfo);
    }

    @GetMapping("/recommendList")
    public ResponseResult recommendList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize", required = false, defaultValue = "7") Integer pageSize,
                                        HttpServletRequest request) {
        String jwtToken = request.getHeader("jwtToken");
        RecommendListVoPageInfo pageInfo = recommendService.recommendList(jwtToken, pageNum, pageSize);
        return new ResponseResult(200, "ok", pageInfo);
    }

    @GetMapping("/select")
    public ResponseResult selectCourse(HttpServletRequest request, Integer id) {
        String jwtToken = request.getHeader("jwtToken");
        Integer result = selectService.selectCourse(jwtToken, id);
        return new ResponseResult(200, "ok", result);
    }

    @GetMapping("/mySelect")
    public ResponseResult mySelectList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", required = false, defaultValue = "7") Integer pageSize,
                                       HttpServletRequest request) {
        String jwtToken = request.getHeader("jwtToken");
        MySelectListVoPageInfo pageInfo = selectService.mySelectList(jwtToken, pageNum, pageSize);
        return new ResponseResult(200, "ok", pageInfo);
    }

    @GetMapping("/cancel")
    public ResponseResult cancelCourse(HttpServletRequest request, Integer id) {
        String jwtToken = request.getHeader("jwtToken");
        Integer result = selectService.cancelCourse(jwtToken, id);
        return new ResponseResult(200, "ok", result);
    }
}
